package com.example.userpage.config;

import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
public class DataSourceConfig {
    @Bean(name = "messageDataSource")
    @ConfigurationProperties(prefix = "spring.datasource.message")
    public DataSource messageDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "logsDataSource")
    @ConfigurationProperties(prefix = "spring.datasource-logs")
    public DataSource logsDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "votesDataSource")
    @ConfigurationProperties(prefix = "spring.datasource-votes")
    public DataSource votesDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean(name = "jdbcMessage")
    public JdbcTemplate jdbcMessage(@Qualifier("messageDataSource") DataSource ds) {
        return new JdbcTemplate(ds);
    }

    @Bean(name = "jdbcLogs")
    public JdbcTemplate jdbcLogs(@Qualifier("logsDataSource") DataSource ds) {
        return new JdbcTemplate(ds);
    }

    @Bean(name = "jdbcVotes")
    public JdbcTemplate jdbcVotes(@Qualifier("votesDataSource") DataSource ds) {
        return new JdbcTemplate(ds);
    }
}